class Solution {
#define FOR(i, b, e) for(int i = b; i < e; ++i)
public:
    void setZeroes(vector<vector<int>>& matrix)
    {
        int rows = matrix.size(), cols = matrix[0].size();
        bool r_0 = false, c_0 = false;
        FOR(r, 0, rows) if(matrix[r][0] == 0) r_0 = true;
        FOR(c, 0, cols) if(matrix[0][c] == 0) c_0 = true;
        FOR(r, 1, rows) FOR(c, 1, cols) if(matrix[r][c] == 0) matrix[r][0] = matrix[0][c] = 0;
        FOR(r, 1, rows) if(matrix[r][0] == 0) FOR(c, 1, cols) matrix[r][c] = 0;
        FOR(c, 1, cols) if(matrix[0][c] == 0) FOR(r, 1, rows) matrix[r][c] = 0;
        if(r_0) FOR(r, 0, rows) matrix[r][0] = 0;
        if(c_0) FOR(c, 0, cols) matrix[0][c] = 0;
    }
};